package com.example.demo.mapper;

import com.example.demo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("INSERT INTO users(username,email,password) VALUES(#{username},#{email},#{password})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertUser(User user);

    @Select("SELECT * FROM users WHERE id = #{id}")
    User selectUserById(Long id);

    @Select("SELECT * FROM users WHERE username = #{username}")
    User selectUserByUsername(String username);

    @Select("SELECT * FROM users WHERE email = #{email}")
    User  selectUserByEmail(String email);

    @Select("SELECT * FROM users")
    List<User> selectAll();

    @Update("UPDATE users SET username = #{username}, email = #{email}, password = #{password}, updated_at = #{updated_at} WHERE id = #{id}")
    int updateUser(User user);

    @Delete("DELETE FROM users WHERE id = #{id}")
    int deleteUser(Long id);

    List<User> selectByStatus(Integer status);


}